file chooser button: Fix some refcounting confusion
authorMatthias Clasen <mclasen@redhat.com>
Thu, 6 Aug 2015 12:51:25 +0000 (14:51 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 6 Aug 2015 12:51:25 +0000 (14:51 +0200)
commitdefc0cf5df61cf556f7f0afbb9e7e4d118313cc2
tree49376ba5f9348ca10793af2ef244d4a8f039dffa
parentf0a1a0c0a42d1ba82be967fbbf7219ea27c11ebd
file chooser button: Fix some refcounting confusion

GtkFileSystem has a complicated way to handle cancellables.
You keep the cancellable pointer that is returned by
_gtk_file_system_get_info and similar methods so that you can
cancel the operation, but you do not own a reference to it.
The only place where it is ok to unref a cancellable is in
your callback, which gets handed a cancellable that you need
to unref at the end. You are expected to compare it to the
pointer you stashed away to find out if the operation has
already been superseded by a newer call, in which case you
disregard the results.

GtkFileChooserButton was following these rules for most of
the cancellables it keeps around, but it was sometimes unreffing
the cancellables that are stored in the model, which could lead
to refcount confusion and crashes. This commit makes it follow
the rules for that case too, which fixes the crash in the bug
below, and does not show up any leaks in valgrind under light
testing.

https://bugzilla.gnome.org/show_bug.cgi?id=737804
gtk/gtkfilechooserbutton.c